home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / CT Explorer / PCIBirdWrapper.cs < prev    next >
Text File  |  2005-05-23  |  15KB  |  464 lines

  1. //PCIBirdWrapper.cs
  2. ////////////////////////////////////////////////////////////////////////////////////
  3. //    This Wrapper was produced using the pcibird3.h and exporting functions
  4. //  to the PCIBirdAPIFuncs.dll which is imported into this wrapper library.
  5. //    Modifications were made to allow API function calls in C# using marshaling.
  6. //    Not all functionalities were added. None of the Get____Status(), Errorhandling,
  7. //    System restore and saving have been implemented. Additionally, the only position 
  8. //  structure presently supported is the old DOUBLE_POSITION_ANGLES (default) data type
  9. //    (Renamed here as 'PositionAnglesReading' class type)
  10. //
  11. //    This file is broken into 3 parts: Enumerations, structured classes, and methods.
  12. //    Note that the original API reference calls imported here use a slightly different
  13. //    name and are augmented with the 'g_' syntax. 
  14. //////////////////////////////////////////////////////////////////////////////////// 
  15.  
  16. using System;
  17. using System.Text;
  18. using System.ComponentModel;
  19. using System.Runtime.InteropServices;
  20.  
  21.  
  22. namespace PCIBird
  23. {
  24.  
  25.     //*************************************************************
  26.     //**                ENUMERATIONS                             **
  27.     //*************************************************************
  28.  
  29.     public enum AGC_MODE_TYPE
  30.     {
  31.         TRANSMITTER_AND_SENSOR_AGC,        // Old style normal addressing mode
  32.         SENSOR_AGC_ONLY                    // Old style extended addressing mode
  33.     }
  34.  
  35.     public enum DEVICE_TYPES
  36.     {
  37.         STANDARD_SENSOR,                // standard sensor
  38.         TYPE_800_SENSOR,                // 8mm sensor
  39.         STANDARD_TRANSMITTER,            // 
  40.         MINIBIRD_TRANSMITTER,            //
  41.         SMALL_TRANSMITTER,                // "compact" transmitter
  42.         TYPE_500_SENSOR,                // 5mm sensor
  43.         TYPE_180_SENSOR,                // microsensor
  44.         UNKNOWN_SENSOR,                    // default
  45.         UNKNOWN_TRANSMITTER                // default
  46.     }
  47.  
  48.     public enum BOARD_TYPES
  49.     {    
  50.         PCIBIRDII,                        // <obsolete>
  51.         PCIBIRD_STD1,                    // single standard sensor
  52.         PCIBIRD_STD2,                    // dual standard sensor
  53.         PCIBIRD_8mm1,                    // single 8mm sensor
  54.         PCIBIRD_8mm2,                    // dual 8mm sensor
  55.         PCIBIRD_2mm1,                    // single 2mm sensor (microsensor)
  56.         PCIBIRD_2mm2,                    // dual 2mm sensor (microsensor)
  57.         PCIBIRD_UNKNOWN                    // default
  58.     }
  59.  
  60.     public enum SYSTEM_PARAMETER_TYPE
  61.     {
  62.         SELECT_TRANSMITTER,        // short int equal to transmitterID of selected transmitter
  63.         POWER_LINE_FREQUENCY,    // double value (range is hardware dependent)
  64.         AGC_MODE,                // enumerated constant of type AGC_MODE_TYPE
  65.         MEASUREMENT_RATE,        // double value (range is hardware dependent)
  66.         MAXIMUM_RANGE,            // double value (range is hardware dependent)
  67.         METRIC,                    // boolean value to select metric units for position
  68.         END_OF_LIST                // end of list place holder
  69.     }
  70.  
  71.     public enum SENSOR_PARAMETER_TYPE
  72.     {                            
  73.         DATA_FORMAT,            // enumerated constant of type DATA_FORMAT_TYPE
  74.         ANGLE_ALIGN,            // structure of type DOUBLE_ANGLES_RECORD
  75.         HEMISPHERE,                // enumerated constant of type HEMISPHERE_TYPE
  76.         FILTER_AC_WIDE_NOTCH,    // boolean value to select/deselect filter
  77.         FILTER_AC_NARROW_NOTCH,    // boolean value to select/deselect filter
  78.         FILTER_DC_ADAPTIVE,        // double value in range 0.0 (no filtering) to 1.0 (max)
  79.         FILTER_ALPHA_PARAMETERS,// structure of type ADAPTIVE_PARAMETERS
  80.         FILTER_LARGE_CHANGE,    // boolean value to select/deselect filter
  81.         QUALITY,                // structure of type QUALITY_PARAMETERS
  82.         SERIAL_NUMBER_RX,        // attached sensor's serial number
  83.         END_OF_RX_LIST
  84.     }
  85.  
  86.     public enum XMTR_PARAMETER_TYPE
  87.     {
  88.         SERIAL_NUMBER_TX,        // attached transmitter's serial number
  89.         REFERENCE_FRAME,        // structure of type DOUBLE_ANGLES_RECORD
  90.         XYZ_REFERENCE_FRAME,    // boolean value to select/deselect mode
  91.         END_OF_TX_LIST
  92.     }
  93.  
  94.     public enum BOARD_PARAMETER_TYPE
  95.     {
  96.         SERIAL_NUMBER_PCB,        // installed board's serial number
  97.         END_OF_PCB_LIST
  98.     }
  99.  
  100.     public enum DATA_FORMAT_TYPE
  101.     {
  102.         NO_FORMAT_SELECTED=0,
  103.  
  104.         // SHORT (integer) formats
  105.         SHORT_POSITION,
  106.         SHORT_ANGLES,
  107.         SHORT_MATRIX,
  108.         SHORT_QUATERNIONS,
  109.         SHORT_POSITION_ANGLES,
  110.         SHORT_POSITION_MATRIX,
  111.         SHORT_POSITION_QUATERNION,
  112.  
  113.         // DOUBLE (floating point) formats
  114.         DOUBLE_POSITION,
  115.         DOUBLE_ANGLES,
  116.         DOUBLE_MATRIX,
  117.         DOUBLE_QUATERNIONS,
  118.         DOUBLE_POSITION_ANGLES,        // system default
  119.         DOUBLE_POSITION_MATRIX,
  120.         DOUBLE_POSITION_QUATERNION,
  121.  
  122.         // DOUBLE (floating point) formats with time stamp appended
  123.         DOUBLE_POSITION_TIME_STAMP,
  124.         DOUBLE_ANGLES_TIME_STAMP,
  125.         DOUBLE_MATRIX_TIME_STAMP,
  126.         DOUBLE_QUATERNIONS_TIME_STAMP,
  127.         DOUBLE_POSITION_ANGLES_TIME_STAMP,
  128.         DOUBLE_POSITION_MATRIX_TIME_STAMP,
  129.         DOUBLE_POSITION_QUATERNION_TIME_STAMP,
  130.  
  131.         // DOUBLE (floating point) formats with time stamp appended and quality #
  132.         DOUBLE_POSITION_TIME_Q,
  133.         DOUBLE_ANGLES_TIME_Q,
  134.         DOUBLE_MATRIX_TIME_Q,
  135.         DOUBLE_QUATERNIONS_TIME_Q,
  136.         DOUBLE_POSITION_ANGLES_TIME_Q,
  137.         DOUBLE_POSITION_MATRIX_TIME_Q,
  138.         DOUBLE_POSITION_QUATERNION_TIME_Q,
  139.  
  140.         // These DATA_FORMAT_TYPE codes contain every format in a single structure
  141.         SHORT_ALL,
  142.         DOUBLE_ALL,
  143.         DOUBLE_ALL_TIME_STAMP,
  144.         DOUBLE_ALL_TIME_STAMP_Q,
  145.         DOUBLE_ALL_TIME_STAMP_Q_RAW,    // this format contains a raw data matrix and
  146.         // is for factory use only...
  147.         MAXIMUM_FORMAT_CODE
  148.     }
  149.  
  150.     public enum HEMISPHERE_TYPE
  151.     {
  152.         FRONT,
  153.         BACK,
  154.         TOP,
  155.         BOTTOM,
  156.         LEFT,
  157.         RIGHT
  158.     }
  159.  
  160.     public enum TRANSMITTER_PARAMETER_TYPE
  161.     {
  162.         SERIAL_NUMBER_TX,        // attached transmitter's serial number
  163.         REFERENCE_FRAME,        // structure of type DOUBLE_ANGLES_RECORD
  164.         XYZ_REFERENCE_FRAME,    // boolean value to select/deselect mode
  165.         END_OF_TX_LIST
  166.     }
  167.  
  168.  
  169.     //*************************************************************
  170.     //**                Structured Classes                         **
  171.     //*************************************************************
  172.  
  173.     [StructLayout(LayoutKind.Sequential)]
  174.     public class SystemConfig
  175.     {    
  176.         public double            measurementRate;
  177.         public double            powerLineFrequency;
  178.         public double            maximumRange;
  179.         public AGC_MODE_TYPE    agcMode;    
  180.         public int                numberBoards;
  181.         public int                numberSensors;
  182.         public int                numberTransmitters;
  183.         public int                transmitterIDRunning;
  184.         public int                metric;
  185.     }
  186.  
  187.     [StructLayout(LayoutKind.Sequential)]
  188.     public class XmtrConfig
  189.     {
  190.         public ulong        serialNumber;
  191.         public DEVICE_TYPES    type;
  192.         public int            attached;
  193.         public ushort        boardNumber;
  194.         public ushort        channelNumber;
  195.     }
  196.  
  197.     [StructLayout(LayoutKind.Sequential)]
  198.     public class SensorConfig
  199.     {
  200.         public ushort        serialNumber;
  201.         public ushort        boardNumber;
  202.         public ushort        channelNumber;
  203.         public DEVICE_TYPES    type;
  204.         public int            attached;
  205.     }
  206.  
  207.     [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
  208.     public class BoardConfig
  209.     {
  210.         public ushort        serialNumber;
  211.         public BOARD_TYPES    type;
  212.         public ushort        revision;
  213.         public ushort        numberTransmitters;
  214.         public ushort        numberSensors;
  215.         public ushort        firmwareNumber;
  216.         public ushort        firmwareRevision;
  217.         [MarshalAs(UnmanagedType.ByValTStr, SizeConst=10)]public string        modelString;
  218.     }
  219.  
  220.     [StructLayout(LayoutKind.Sequential)]
  221.     public class PositionAnglesReading
  222.     {
  223.         public double x;
  224.         public double y;
  225.         public double z;
  226.         public double a;
  227.         public double e;
  228.         public double r;
  229.     }
  230.  
  231.     [StructLayout(LayoutKind.Sequential)]
  232.     public class AnglesReading
  233.     {
  234.         public double    a;            // azimuth
  235.         public double    e;            // elevation
  236.         public double    r;            // roll
  237.     }
  238.  
  239.  
  240.     [StructLayout(LayoutKind.Sequential)]
  241.     public class AdaptiveParameters
  242.     {
  243.         [MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
  244.         public ushort[] alphaMin; 
  245.         [MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
  246.         public ushort[] alphaMax;
  247.         [MarshalAs(UnmanagedType.ByValArray, SizeConst=7)]
  248.         public ushort[] vm; 
  249.         public int    alphaOn;
  250.     }
  251.  
  252.     [StructLayout(LayoutKind.Sequential)]
  253.     public class QualityParameters
  254.     {
  255.         public ushort    errorSlope;            
  256.         public ushort    errorOffset;            
  257.         public ushort    errorSensitivity;    
  258.         public ushort    filterAlpha;    
  259.     }
  260.  
  261.  
  262.  
  263.     //***********************************************************
  264.     public class PCIBirdWrapper
  265.     {
  266.  
  267.         //Imported DLL functions--------------------------------
  268.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  269.         public static extern int g_InitializeSystem();
  270.  
  271.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  272.         public static extern int g_GetSystemConfig(
  273.             [MarshalAs(UnmanagedType.LPStruct)]
  274.             SystemConfig lpsc );
  275.  
  276.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  277.         public static extern int g_GetXmtrConfig(
  278.             uint xmtrID, [In, MarshalAs(UnmanagedType.LPStruct)]
  279.             XmtrConfig lpxc);
  280.  
  281.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  282.         public static extern int g_GetSensorConfig(
  283.             uint sensorID, [In, MarshalAs(UnmanagedType.LPStruct)]
  284.             SensorConfig lpsc);
  285.  
  286.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  287.         public static extern int g_GetBoardConfig(
  288.             uint boardID, [In,Out, MarshalAs(UnmanagedType.LPStruct)]
  289.             BoardConfig lpbc);
  290.  
  291.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  292.         public static extern int g_GetAsyncSensorReading(
  293.             ushort sensorID, [In,Out, MarshalAs(UnmanagedType.AsAny)]
  294.             object o, int objectSize );
  295.  
  296.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  297.         public static extern int g_GetSyncSensorReading(
  298.             ushort sensorID, [In,Out, MarshalAs(UnmanagedType.AsAny)]
  299.             object o, int objectSize);
  300.  
  301.         //------------GetSystemParam METHOD-------------
  302.  
  303.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  304.         public static extern int g_GetSystemParam(    
  305.             SYSTEM_PARAMETER_TYPE paramType, 
  306.             [In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
  307.  
  308.         //----------------------SetSystemParam METHOD-------------
  309.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  310.         public static extern int g_SetSystemParam(
  311.             SYSTEM_PARAMETER_TYPE paramType, 
  312.             [In, MarshalAs(UnmanagedType.AsAny)]
  313.             object o, int bufferSize);
  314.         //------------GetSensorParam METHODS-------------
  315.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  316.         public static extern int g_GetSensorParam(    //get struct data
  317.             ushort sensorID, SENSOR_PARAMETER_TYPE paramType, 
  318.             [In,Out, MarshalAs(UnmanagedType.AsAny)] object o, 
  319.             int bufferSize);
  320.  
  321.         //----------------------SetSensorParam METHODS-------------
  322.  
  323.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  324.         public static extern int g_SetSensorParam(    //get struct data
  325.             ushort sensorID, SENSOR_PARAMETER_TYPE paramType, 
  326.             [In, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
  327.  
  328.         //------------GetXmtrParam Methods----------------
  329.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  330.         public static extern int g_GetXmtrParam( //get struct data
  331.             ushort xmtrID, XMTR_PARAMETER_TYPE paramType, 
  332.             [In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
  333.  
  334.         //----------------------SetXmtrParam Methods------------------
  335.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  336.         public static extern int g_SetXmtrParam(
  337.             ushort xmtrID, XMTR_PARAMETER_TYPE paramType, 
  338.             [In, MarshalAs(UnmanagedType.AsAny)]
  339.             object o, int bufferSize);
  340.  
  341.         //----------------------GetBoardParam Methods------------------
  342.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  343.         public static extern int g_GetBoardParam( //get struct data
  344.             ushort boardID, BOARD_PARAMETER_TYPE paramType, 
  345.             [In,Out, MarshalAs(UnmanagedType.AsAny)] object o, int bufferSize);
  346.  
  347.         //-------------------------------------------------------------------
  348.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  349.         public static extern int g_SetBoardParam(
  350.             ushort boardID, BOARD_PARAMETER_TYPE paramType, 
  351.             [In, MarshalAs(UnmanagedType.AsAny)]
  352.             object o);
  353.  
  354.         [DllImport("PCIBirdAPIFuncs.dll", CharSet=CharSet.Auto)]
  355.         public static extern int g_ShutdownSystem();
  356.  
  357.         //Class Methods-----------------------------------------
  358.         public int InitializeSystem()
  359.         {
  360.             return g_InitializeSystem();
  361.         }
  362.  
  363.         public SystemConfig GetSystemConfig()
  364.         {
  365.             SystemConfig systemConfig = new SystemConfig();
  366.             int errorCode = g_GetSystemConfig( systemConfig );
  367.             return systemConfig;
  368.         }
  369.  
  370.         public XmtrConfig GetXmtrConfig(uint xmtrID)
  371.         {
  372.             XmtrConfig xmtrConfig = new XmtrConfig();
  373.             g_GetXmtrConfig(xmtrID,xmtrConfig);
  374.             return xmtrConfig;
  375.         }
  376.  
  377.         public SensorConfig GetSensorConfig(uint sensorID)
  378.         {
  379.             SensorConfig sensorConfig = new SensorConfig();
  380.             g_GetSensorConfig(sensorID,sensorConfig);
  381.             return sensorConfig;
  382.         }
  383.  
  384.         public BoardConfig GetBoardConfig(uint boardID)
  385.         {
  386.             BoardConfig boardConfig = new BoardConfig();
  387.             g_GetBoardConfig(boardID,boardConfig);
  388.             return boardConfig;
  389.         }
  390.  
  391.         public void GetAsyncSensorReading(ushort sensorID, object o, int objectSize)
  392.         {
  393.             g_GetAsyncSensorReading(sensorID,o,objectSize);
  394.         }
  395.  
  396.         public void GetSyncSensorReading(ushort sensorID, object o, int objectSize)
  397.         {
  398.             g_GetSyncSensorReading(sensorID,o,objectSize);
  399.         }
  400.     
  401.         //-------------GetSystemParam-----------------------------------//
  402.         public void GetSystemParam(SYSTEM_PARAMETER_TYPE paramType, 
  403.             object o, int bufferSize)
  404.         {
  405.             g_GetSystemParam(paramType,o,bufferSize);
  406.         }
  407.  
  408.         //-------------SetSystemParam-----------------------------------//
  409.         public void SetSystemParam(SYSTEM_PARAMETER_TYPE paramType,
  410.             object o, int bufferSize)
  411.         {
  412.             g_SetSystemParam(paramType,o, bufferSize);
  413.         }
  414.  
  415.         //-------------GetSensorParam-----------------------------------//
  416.         public void GetSensorParam(ushort sensorID,//structure param
  417.             SENSOR_PARAMETER_TYPE paramType, object o, int bufferSize)
  418.         {
  419.             g_GetSensorParam(sensorID,paramType,o,bufferSize);
  420.         }
  421.  
  422.         //------------SetSensorParam------------------------------------//
  423.  
  424.         public void SetSensorParam(ushort sensorID,
  425.             SENSOR_PARAMETER_TYPE paramType, object o, int bufferSize)
  426.         {
  427.             g_SetSensorParam(sensorID,paramType,o,bufferSize);
  428.         }
  429.     
  430.         //------------GetXmtrParam------------------------------------//
  431.         public void GetXmtrParam(ushort xmtrID, //structure param
  432.             XMTR_PARAMETER_TYPE paramType, object o, int bufferSize )
  433.         {
  434.             g_GetXmtrParam(xmtrID,paramType,o,bufferSize);
  435.         }
  436.     
  437.         //------------SetXmtrParam------------------------------------//
  438.         public void SetXmtrParam(ushort xmtrID,
  439.             XMTR_PARAMETER_TYPE paramType, object o, int bufferSize)
  440.         {
  441.             g_SetXmtrParam(xmtrID,paramType, o, bufferSize);
  442.         }
  443.  
  444.         //------------GetBoardParam------------------------------------//
  445.         public void GetBoardParam(ushort boardID, //int param
  446.             BOARD_PARAMETER_TYPE paramType, object o, int bufferSize)
  447.         {
  448.             g_GetBoardParam(boardID,paramType,o,bufferSize);
  449.         }
  450.         //------------SetBoardParam------------------------------------//
  451.         public void SetBoardParam(ushort boardID,
  452.             BOARD_PARAMETER_TYPE paramType, object o)
  453.         {
  454.             g_SetBoardParam(boardID,paramType,o);
  455.         }
  456.         /// <summary>
  457.         /// skipped a bunch of functions right here --> add in later
  458.         /// </summary>
  459.         public void ShutdownSystem()
  460.         {
  461.             g_ShutdownSystem();
  462.         }
  463.     }
  464. }